
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/17/2011 18:10:58
-- Generated from EDMX file: G:\Visual Studio 2010\Projects\Auction\Auction\EDM_Auction.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [auction_db];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_BidderBid]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BidSet] DROP CONSTRAINT [FK_BidderBid];
GO
IF OBJECT_ID(N'[dbo].[FK_AuctionBid]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BidSet] DROP CONSTRAINT [FK_AuctionBid];
GO
IF OBJECT_ID(N'[dbo].[FK_PackageWorkOfArt]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkOfArtSet] DROP CONSTRAINT [FK_PackageWorkOfArt];
GO
IF OBJECT_ID(N'[dbo].[FK_AuctionPackage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PackageSet] DROP CONSTRAINT [FK_AuctionPackage];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[BidderSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BidderSet];
GO
IF OBJECT_ID(N'[dbo].[BidSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BidSet];
GO
IF OBJECT_ID(N'[dbo].[AuctionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AuctionSet];
GO
IF OBJECT_ID(N'[dbo].[PackageSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PackageSet];
GO
IF OBJECT_ID(N'[dbo].[WorkOfArtSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkOfArtSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'BidderSet'
CREATE TABLE [dbo].[BidderSet] (
    [idBidder] int IDENTITY(1,1) NOT NULL,
    [nameBidder] nvarchar(max)  NOT NULL,
    [Bond] decimal(18,0)  NOT NULL,
    [Surname1] nvarchar(max)  NOT NULL,
    [Surname2] nvarchar(max)  NULL,
    [Telephone] nchar(9)  NOT NULL,
    [Sex] nvarchar(max)  NULL,
    [Passport] nvarchar(max)  NOT NULL,
    [Adress] nvarchar(max)  NULL,
    [NumberAdress] tinyint  NULL,
    [Town] nvarchar(max)  NULL,
    [City] nvarchar(max)  NULL,
    [Country] nvarchar(max)  NULL,
    [Account] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'BidSet'
CREATE TABLE [dbo].[BidSet] (
    [idBid] int IDENTITY(1,1) NOT NULL,
    [Date] datetime  NOT NULL,
    [Amount] decimal(18,0)  NOT NULL,
    [Bidder_idBidder] int  NOT NULL,
    [Auction_idAuction] int  NOT NULL
);
GO

-- Creating table 'AuctionSet'
CREATE TABLE [dbo].[AuctionSet] (
    [idAuction] int IDENTITY(1,1) NOT NULL,
    [nameAuction] nvarchar(max)  NOT NULL,
    [dateAuction] datetime  NOT NULL,
    [active] bit  NOT NULL
);
GO

-- Creating table 'PackageSet'
CREATE TABLE [dbo].[PackageSet] (
    [idPackage] int IDENTITY(1,1) NOT NULL,
    [minimunSellingPrice] decimal(18,0)  NOT NULL,
    [outputPrice] decimal(18,0)  NOT NULL,
    [sold] bit  NOT NULL,
    [description] nvarchar(max)  NOT NULL,
    [nameOfPackage] nvarchar(max)  NOT NULL,
    [putUpForSale] bit  NOT NULL,
    [Auction_idAuction] int  NULL
);
GO

-- Creating table 'WorkOfArtSet'
CREATE TABLE [dbo].[WorkOfArtSet] (
    [idWorkOfArt] int IDENTITY(1,1) NOT NULL,
    [nameOfWork] nvarchar(max)  NOT NULL,
    [year] tinyint  NOT NULL,
    [AuthorName] nvarchar(max)  NOT NULL,
    [AuthorSurname] nvarchar(max)  NOT NULL,
    [typeOfWorkOfArt] nvarchar(max)  NOT NULL,
    [Package_idPackage] int  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [idBidder] in table 'BidderSet'
ALTER TABLE [dbo].[BidderSet]
ADD CONSTRAINT [PK_BidderSet]
    PRIMARY KEY CLUSTERED ([idBidder] ASC);
GO

-- Creating primary key on [idBid] in table 'BidSet'
ALTER TABLE [dbo].[BidSet]
ADD CONSTRAINT [PK_BidSet]
    PRIMARY KEY CLUSTERED ([idBid] ASC);
GO

-- Creating primary key on [idAuction] in table 'AuctionSet'
ALTER TABLE [dbo].[AuctionSet]
ADD CONSTRAINT [PK_AuctionSet]
    PRIMARY KEY CLUSTERED ([idAuction] ASC);
GO

-- Creating primary key on [idPackage] in table 'PackageSet'
ALTER TABLE [dbo].[PackageSet]
ADD CONSTRAINT [PK_PackageSet]
    PRIMARY KEY CLUSTERED ([idPackage] ASC);
GO

-- Creating primary key on [idWorkOfArt] in table 'WorkOfArtSet'
ALTER TABLE [dbo].[WorkOfArtSet]
ADD CONSTRAINT [PK_WorkOfArtSet]
    PRIMARY KEY CLUSTERED ([idWorkOfArt] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Bidder_idBidder] in table 'BidSet'
ALTER TABLE [dbo].[BidSet]
ADD CONSTRAINT [FK_BidderBid]
    FOREIGN KEY ([Bidder_idBidder])
    REFERENCES [dbo].[BidderSet]
        ([idBidder])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BidderBid'
CREATE INDEX [IX_FK_BidderBid]
ON [dbo].[BidSet]
    ([Bidder_idBidder]);
GO

-- Creating foreign key on [Auction_idAuction] in table 'BidSet'
ALTER TABLE [dbo].[BidSet]
ADD CONSTRAINT [FK_AuctionBid]
    FOREIGN KEY ([Auction_idAuction])
    REFERENCES [dbo].[AuctionSet]
        ([idAuction])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AuctionBid'
CREATE INDEX [IX_FK_AuctionBid]
ON [dbo].[BidSet]
    ([Auction_idAuction]);
GO

-- Creating foreign key on [Package_idPackage] in table 'WorkOfArtSet'
ALTER TABLE [dbo].[WorkOfArtSet]
ADD CONSTRAINT [FK_PackageWorkOfArt]
    FOREIGN KEY ([Package_idPackage])
    REFERENCES [dbo].[PackageSet]
        ([idPackage])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PackageWorkOfArt'
CREATE INDEX [IX_FK_PackageWorkOfArt]
ON [dbo].[WorkOfArtSet]
    ([Package_idPackage]);
GO

-- Creating foreign key on [Auction_idAuction] in table 'PackageSet'
ALTER TABLE [dbo].[PackageSet]
ADD CONSTRAINT [FK_AuctionPackage]
    FOREIGN KEY ([Auction_idAuction])
    REFERENCES [dbo].[AuctionSet]
        ([idAuction])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AuctionPackage'
CREATE INDEX [IX_FK_AuctionPackage]
ON [dbo].[PackageSet]
    ([Auction_idAuction]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------